package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;



/**
 * Created by yepeng on 2016/4/22.
 */
public abstract class CommonListAdapter<T> extends BaseAdapter {
    List<T> list;
    Context context;
    int itemLayoutResId;

    public CommonListAdapter(T t, Context context, int itemLayoutResId) {
        this.list = new ArrayList<>();
        this.list.add(t);
        for (int i = 0; i < 4; i++) {
            this.list .addAll(list);
        }
        this.context = context;
        this.itemLayoutResId = itemLayoutResId;
    }
    public void  addItem(T t){
        this.list.clear();
        this.list.add(t);
        for (int i = 0; i < 4; i++) {
            list.addAll(list);
        }

        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public T getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CategoryCommonViewHolder holder = new CategoryCommonViewHolder(context, convertView, itemLayoutResId);
        bindData(holder, list, position);
        return holder.convertView;
    }

    protected abstract void bindData(CategoryCommonViewHolder holder, List<T> list, int position);

}
